home *** CD-ROM | disk | FTP | other *** search
/ Die Speccy' 97 / Die Speccy' 97.iso / amiga_system / the_aminet / comm / bbs / s342q07.lha / sysedit.c < prev    next >
C/C++ Source or Header  |  1993-03-26  |  5KB  |  167 lines

  1. /************************************************************************/
  2. /*        sysedit.c             */
  3. /*                  */
  4. /*  Message Editor facilities.          */
  5. /************************************************************************/
  6. /************************************************************************/
  7. /*        history         */
  8. /*                  */
  9. /* 89Nov12 AP Created.              */
  10. /************************************************************************/
  11. #define SYSTEM_DEPENDENT
  12. #include "ctdl.h"
  13. /************************************************************************/
  14. /*        Contents        */
  15. /*                  */
  16. /*  OutsideEditor()   use an outside editor for sysop.  */
  17. /************************************************************************/
  18. typedef struct
  19.   {
  20.   char *Name;
  21.   char *CmdLine;
  22.  
  23.   }
  24. Editor;
  25.  
  26. int UnQueueSerRead(void);
  27. int QueueSerRead(int);
  28. int Jsystem(char *);
  29.  
  30.  
  31. static void *EatEditorLine(char *line);
  32. void *FindEditorSelector();
  33. static SListBase ExtEditors =
  34.   {
  35.   NULL, FindEditorSelector, NULL, NULL,
  36.   EatEditorLine
  37.  
  38.   };
  39. static char **TheOpts;
  40. extern CONFIG  cfg;            /* Lots an lots of variables    */
  41. extern MessageBuffer msgBuf;         /* Message buffer               */
  42. void OutsideEditorWork(char *EditLine);
  43. /************************************************************************/
  44. /*  OutsideEditor() use an outside editor for sysop.    */
  45. /************************************************************************/
  46. void OutsideEditor()
  47.   {
  48.   OutsideEditorWork(cfg.DepData.Editor);
  49.  
  50.   }
  51. /************************************************************************/
  52. /*  OutsideEditorWork() execute an outside editor.      */
  53. /************************************************************************/
  54. void ReActivate_Window(void);
  55. void OutsideEditorWork(char *EditLine)
  56.   {
  57.   char cmdline[120];
  58.   extern FILE *upfd;
  59.   extern int outPut;
  60.   doCR(); /* this gets crtColumn back to zero */
  61.   sPrintf(cmdline, "%stempmsg.sys", cfg.DepData.EditArea);
  62.   if (!redirect(cmdline)) return;
  63.   mFormat(msgBuf.mbtext);
  64.   undirect();
  65.   MakeCmdLine(cmdline, EditLine, "", sizeof cmdline - 1);
  66.   sPrintf(lbyte(cmdline), " %stempmsg.sys", cfg.DepData.EditArea);
  67.   UnQueueSerRead();
  68.   Jsystem(cmdline);
  69.   ReActivate_Window();   /* AmigaDos: Make console active and front */
  70.   QueueSerRead(8);
  71.   homeSpace();
  72.   msgBuf.mbtext[0] = 0;
  73.   sPrintf(cmdline, "%stempmsg.sys", cfg.DepData.EditArea);
  74.   ingestFile(cmdline, &msgBuf);
  75.   unlink(cmdline);
  76.  
  77.   }
  78. /************************************************************************/
  79. /*  InitExternEditors() initialization function.      */
  80. /************************************************************************/
  81. void InitExternEditors()
  82.   {
  83.   SYS_FILE fn;
  84.   makeSysName(fn, "editors.sys", &cfg.roomArea);
  85.   MakeList(&ExtEditors, fn, NULL);
  86.  
  87.   }
  88. /************************************************************************/
  89. /*  EatEditorLine() eat a line from editors.sys.      */
  90. /*  format is "<selector letter> <s.name> <command line>"   */
  91. /************************************************************************/
  92. static void *EatEditorLine(char *line)
  93.   {
  94.   Editor *work;
  95.   char   *c;
  96.   if ((c = strchr(line, ' ')) == NULL) return NULL;
  97.   if (line[0] == '"')
  98.     {
  99.     line++;
  100.     if ((c = strchr(line, '"')) == NULL) return NULL;
  101.     *c = 0;
  102.     c++;
  103.  
  104.     }
  105.   *c = 0;
  106.   work = GetDynamic(sizeof *work);
  107.   work->Name = strdup(line);
  108.   work->CmdLine = strdup(c + 1);
  109.   return work;
  110.  
  111.   }
  112. /************************************************************************/
  113. /*  OtherEditOptions() add options to the editor menu.    */
  114. /************************************************************************/
  115. void OtherEditOptions(char **Options)
  116.   {
  117.   void AddOurEditOpts();
  118.   TheOpts = Options;
  119.   RunList(&ExtEditors, AddOurEditOpts);
  120.  
  121.   }
  122. /************************************************************************/
  123. /*  ShowOutsideEditors() show available external editors    */
  124. /************************************************************************/
  125. void ShowOutsideEditors()
  126.   {
  127.   void DisplayEditOpts();
  128.   RunList(&ExtEditors, DisplayEditOpts);
  129.  
  130.   }
  131. /************************************************************************/
  132. /*  DisplayEditOpts() display editing options     */
  133. /************************************************************************/
  134. void DisplayEditOpts(Editor *d)
  135.   {
  136.   mPrintf("<%c>%s\n ", d->Name[0], d->Name + 1);
  137.  
  138.   }
  139. /************************************************************************/
  140. /*  AddOurEditOpts() add an external editor option.     */
  141. /************************************************************************/
  142. void AddOurEditOpts(Editor *d)
  143.   {
  144.   ExtraOption(TheOpts, d->Name);
  145.  
  146.   }
  147. /************************************************************************/
  148. /*  FindEditorSelector() find which editor has been requested.  */
  149. /************************************************************************/
  150. void *FindEditorSelector(Editor *d, int *s)
  151.   {
  152.   if (d->Name[0] == *s)
  153.   return d;
  154.   return NULL;
  155.  
  156.   }
  157. /************************************************************************/
  158. /*  RunRemoteEditor() run any of the extended editors.    */
  159. /************************************************************************/
  160. void RunRemoteEditor(int s)
  161.   {
  162.   Editor *TheEditor;
  163.   if ((TheEditor = SearchList(&ExtEditors, &s)) != NULL)
  164.   OutsideEditorWork(TheEditor->CmdLine);
  165.  
  166.   }
  167.